package org.chen.mybatis.utils;

import org.chen.spring.core.annotation.Autowired;
import org.chen.spring.core.annotation.Component;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author Chen
 * @since 2023/6/9 10:52
 */

@Component
public class ConnectionUtils {

    @Autowired
    private ConnectionProperties properties;

    {
        try {
            if (properties != null) {
                Class.forName(properties.getDriverClassName());
            }
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    public Connection getConnection() throws SQLException {
        return DriverManager.getConnection(properties.getUrl(), properties.getUsername(), properties.getPassword());
    }

}
